package edu.mse.camel.client.session.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPart;

import edu.mse.camel.client.session.team.ITeamMember;
import edu.mse.camel.client.session.team.TEAMMEMBER_STATUS;
import edu.mse.camel.client.session.team.TeamList;
import edu.mse.camel.client.session.views.SessionDialog;

public class SetFacilitatorActionDelegate implements IObjectActionDelegate,
		IViewActionDelegate {

	private ITeamMember iTeamMember;
	
	@Override
	public void init(IViewPart view) {
		// TODO Auto-generated method stub

	}

	@Override
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {

	}

	@Override
	public void run(IAction action) {
		SessionDialog sessionDialog = new SessionDialog();
		sessionDialog.setFacilitator(iTeamMember);

	}

	@Override
	public void selectionChanged(IAction action, ISelection selection) {
		Object o = ((IStructuredSelection) selection).getFirstElement();
		if (o instanceof ITeamMember) {
			iTeamMember = (ITeamMember) o;
			if (iTeamMember.getStatus().equals(TEAMMEMBER_STATUS.SESSION)
					&& TeamList.getInstance().getMe().isFacilitator()) {
				action.setEnabled(true);
			} else {
				action.setEnabled(false);
			}
		}
	}

}
